<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 父组件模板-->
    <div id="app">
        <cpn></cpn>
    </div>  
 <template id="cpn">
    <div>
        <ccpn></ccpn>
    </div>
 </template>
 <template id="ccpn">
    <div>
        <h2>我是子子组件</h2>
        <button @click="btnClick">按钮</button>
    </div>
 </template>
    <script src="../js/vue.js"></script>
    <script>
          //父组件 ------ 双向绑定案例
          const app=new Vue({
            el:'#app',
            components:{
                    //组件名称
                    cpn:{
                        template:"#cpn",
                        data(){
                           return{
                            name: '我是cpn组件的name'
                           }
                        },
                        components:{
                        ccpn:{
                            template:"#ccpn",
                            methods:{
                            btnClick(){
                                //1 访问父组件$parent
                                console.log(this.$parent.name)
                                //2 访问根组件
                                console.log(this.$root)
                            }
                        }
                        },
                        
                    }
                    },
                  
                }
        })
    </script>
</body>
</html>